<?php

require_once 'CObject.php';

$GLOBALS['_CFilterManager'] = &new CFilterChain();

class CStringFilter extends CObject {
	function FilterString($str) {
		return $str;
	}
	
	function FilterEncodedBuffer($buf, $encoding) {
		return $buf;
	}

	function &GetCurrent() {
		return $GLOBALS['_CFilterManager'];
	}
	
	function SetCurrent(&$filterManager) {
		$GLOBALS['_CFilterManager'] = &$filterManager;
	}
	
	function FilterToBufferOfEncoding($str, $encoding) {
		$str = $this->FilterString($str);
		$buf = $str->AsBufferOfEncoding($encoding);
		return $this->FilterEncodedBuffer($buf, $encoding);
	}
}

class CFilterChain extends CStringFilter {
	var $Filters = array();
	
	function AddFilter(&$filter) {
		$this->Filters[] = &$filter;
	}
	
	function FilterString($str) {
		foreach ($this->Filters as $filter)
			$str = $filter->FilterString($filter);
	}
	
	function FilterEncodedBuffer($buf, $encoding) {
		foreach ($this->Filters as $filter)
			$buf = $filter->FilterEncodedBuffer($buf, $encoding);
		
		return $buf;
	}
}

?>